package club.xinghe.servlet.teacher;

import club.xinghe.biz.TkBiz;
import club.xinghe.entity.Tk;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * 修改试题
 * @刘艺广
 */
@WebServlet("/teacher/EditTkServlet")
public class EditTkServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        //得到老师在文本框中输入的试题：问题和选项组成的集合，选项以及答案
        String tContent= request.getParameter("tkValues");
        String tAnswer=request.getParameter("tAnswer");
        int tId=Integer.parseInt(request.getParameter("tId"));

        Tk tk=new Tk(tId,tContent,tAnswer);
        TkBiz tkBiz=new TkBiz();
        int result=tkBiz.editTk(tk);
        PrintWriter out=response.getWriter();
        if(result>0){
            out.print("true");
        }else{
            out.print("false");
        }
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req,resp);
    }
}
